<template>
    <component is="a-modal" v-model:visible="visible" width="50%" :title="title" :mask-closable="false"
      :ok-loading="loading" @cancel="close" @before-ok="submit">
      <div >
        <a-form ref="formRef" :model="formData" :rules="rules" :auto-label-width="true">
          <a-form-item label="订单ID" field="order_id">
            <a-input v-model="formData.order_id" placeholder="请输入" />
          </a-form-item>
          <a-form-item label="操作密码" field="admin_pay_password">
            <a-input-password v-model="formData.admin_pay_password" placeholder="请输入" />
          </a-form-item>
          <a-form-item label="谷歌验证码" field="google_code">
            <a-input v-model="formData.google_code" placeholder="请输入" />
          </a-form-item>
        </a-form>
      </div>
    </component>
  </template>
  <script setup>
  import { onMounted, ref, reactive, computed, watch } from 'vue'
  import funApi from '@/api/message/tool'
  import { Message } from '@arco-design/web-vue'
  import { throttle } from 'lodash';
  import tool from '@/utils/tool'
  const emit = defineEmits(["success"]);
  const formRef = ref()
  const visible = ref(false);
  const title = ref('')
  const loading = ref(false);
  const formData = reactive({
    order_id: '',
    admin_pay_password: '',
    google_code:'',
  })
  const rules = ref({
    order_id: [{ required: true, message: '请输入' }],
    admin_pay_password: [{ required: true, message: '请输入' }],
    google_code: [{ required: true, message: '请输入' }],
  });
  const open = async (data) => {
    visible.value = true;
    formRef.value.resetFields()
    title.value='更新订单支付状态'
    getParams()
  }
  const submit = async (done) => {
    const validate = await formRef.value?.validate()
    if (!validate) {
      loading.value = true
      try {
        let data = { ...formData }
        let result = await funApi.tool_update_paystate(data)
        if (result.code === 200) {
          Message.success('操作成功')
          emit('success')
          done(true)
        }
        setTimeout(() => {
          loading.value = false
        }, 500)
      } catch {
        loading.value = false
      }
    }
    done(false)

}
  const paramsData = ref({})
  const getParams = async () => {
    // const { data } = await memberApi.update_pv_params(formData.id)
    // paramsData.value = { ...data }
  }
  defineExpose({ open });
  </script>